package basic

import (
	"sync"
	"time"
	"github.com/samuel/go-zookeeper/zk"
	log "code.google.com/p/log4go"
	"EasyData/global"
)

var conn *zk.Conn
var once sync.Once

 /**
 	获取单例ZK客户端请使用这个函数，切勿直接使用变量
  */
func GetZkClient() *zk.Conn{
	once.Do(func(){
		zookeeper := global.Config().Zookeeper
		var hosts = []string{zookeeper}//server端host
		var err error
		conn, _, err = zk.Connect(hosts, time.Second*5)
		if err != nil {
			log.Error(err)
			global.PanicError(err,nil)
		}
	})
	return conn
}
